﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.LightSwitch;
namespace LightSwitchApplication
{
    public partial class vEmployeeTreeItem
    {
        partial void TreeSalesAmount_Compute(ref decimal result)
        {
            if (this.SalesAmount != null)
                result = (decimal)this.SalesAmount;

            CalsTreeSalesAmount(ref result, this);
        }

        private decimal CalsTreeSalesAmount(ref decimal result, vEmployeeTreeItem manager)
        {
            foreach (var childEmployee in manager.Employees)
            {
                if (childEmployee.SalesAmount != null)
                    result += (decimal)childEmployee.SalesAmount;

                CalsTreeSalesAmount(ref result, childEmployee);
            }
            return result;
        }
    }
}
